﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FlickrSample.SL.Infrastructure.Flickr.Commands;
using FlickrSample.SL.Infrastructure.Flickr.Entities;
using FlickrSample.SL.Infrastructure.Flickr.Parser;

namespace FlickrSample.SL.Infrastructure.Repo.User.Online
{
    public class UserRepo : IUserRepo
    {
        public void GetPhotoSets(FlickrUser user, Action<List<PhotoSet>> callback)
        {
            var command = new flickr_photosets_getList(user);

            ServiceLocator.FlickrRepo.ExecuteCommand(command, result =>
            {
                if (!string.IsNullOrEmpty(result))
                {
                    var photoSets = PhotoSetParser.ParsePhotoSet(result);
                    callback(photoSets);

                }
                else
                {
                    callback(null);
                }

            });
        }


        public void GetUserDetail(FlickrUser user, Action<bool> callback)
        {
            var command = new flickr_people_getInfo(user.NSID);

            ServiceLocator.FlickrRepo.ExecuteCommand(command, result =>
            {
                if (!string.IsNullOrEmpty(result))
                {
                    UserParser.ParseDetail(user, result);
                    callback(true);
                }
                else
                {
                    callback(false);
                }

            });
        }
    }
}
